package com.sikao.app.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sikao.app.R;
import com.sikao.app.adapter.PicturesAdapter;
import com.sikao.app.bean.ArbitrationResultBean;
import com.sikao.app.bean.BuyerOrderOperateSubmitBean;
import com.sikao.app.dao.BuyerArbitrationResultModel;
import com.sikao.app.dao.SellerArbitrationResultModel;
import com.sikao.app.net.OnNetBackListener;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.JSONUtil;
import com.sikao.app.view.MyGridView;

import java.util.ArrayList;
import java.util.List;


/**
 * 仲裁结果
 */
public class ArbitrationResultActivity extends BaseActivity implements View.OnClickListener {

	private TextView titleTv;
	private ImageView backIv;
	private BuyerArbitrationResultModel buyerArbitrationResultModel;
	private SellerArbitrationResultModel sellerArbitrationResultModel;
	private BuyerOrderOperateSubmitBean orderOperateSubmitBean;
	private TextView tvResult;
	private TextView tvBuyerGetMoney;
	private TextView tvSellerGetMoney;
	private TextView tvPlatformGetMoney;
	private LinearLayout linearlayout;
	private MyGridView gridView;
	private PicturesAdapter adapter;
	private List<String> pictureBeans;
	private String beanId;
	private String type;//buyer 买家订单，seller 卖家订单

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_arbitration_result);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		beanId = getIntent().getStringExtra("bean");
		type = getIntent().getStringExtra("type");
	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		tvResult = (TextView) findViewById(R.id.tv_result);
		tvBuyerGetMoney = (TextView) findViewById(R.id.tv_buyer_get_money);
		tvSellerGetMoney = (TextView) findViewById(R.id.tv_seller_get_money);
		tvPlatformGetMoney = (TextView) findViewById(R.id.tv_platform_get_money);
		linearlayout = (LinearLayout) findViewById(R.id.linearlayout);
		gridView = (MyGridView) findViewById(R.id.gridView);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
	}

	@Override
	protected void init() {
		titleTv.setText("仲裁结果");
		backIv.setVisibility(View.VISIBLE);
		orderOperateSubmitBean = new BuyerOrderOperateSubmitBean();
		orderOperateSubmitBean.setOrderId(beanId);
		orderOperateSubmitBean.setAction("getArbitration");
		if (type.equals("buyer")) {
			buyerArbitrationResultModel = new BuyerArbitrationResultModel(this, new OnNetBackListener<ArbitrationResultBean>() {
				@Override
				public void netBack(ArbitrationResultBean data) {
					if (data == null) {
						return;
					}
					if (data.getStatus().equals("1")){
						showContent(data);
					}else{
						Toast.makeText(ArbitrationResultActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});
			buyerArbitrationResultModel.request(JSONUtil.toJSON(orderOperateSubmitBean), true);
		}else{
			sellerArbitrationResultModel = new SellerArbitrationResultModel(this, new OnNetBackListener<ArbitrationResultBean>() {
				@Override
				public void netBack(ArbitrationResultBean data) {
					if (data.getStatus().equals("1")){
						showContent(data);
					}else{
						Toast.makeText(ArbitrationResultActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});
			sellerArbitrationResultModel.request(JSONUtil.toJSON(orderOperateSubmitBean), true);
		}

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				finish();
				break;
			default:
				break;
		}
	}

	private void showContent(ArbitrationResultBean bean){
		tvResult.setText(bean.getRes().getResult());
		tvBuyerGetMoney.setText(bean.getRes().getUser_price());
		tvSellerGetMoney.setText(bean.getRes().getShop_price());
		tvPlatformGetMoney.setText(bean.getRes().getSite_price());
		pictureBeans = new ArrayList<>();
		pictureBeans.add("http://img.mp.itc.cn/upload/20160512/65b90deeb9a74c4585371ac6e95b25b7_th.jpg");
		pictureBeans.add("http://img.mp.itc.cn/upload/20160512/65b90deeb9a74c4585371ac6e95b25b7_th.jpg");
		adapter =  new PicturesAdapter(this,pictureBeans);
		gridView.setAdapter(adapter);
	}

}
